<template>
  <div>
    <table-view :titles="titles" :dataSource="lists" @next="changePageClick(data)" @previous="changePageClick(data)" :maxPage="maxPage" btn="解绑" @btnClick="unBindClick">
    </table-view>
  </div>
</template>

<script>
import TableView from "../../components/common/TableView.vue";
export default {
  data() {
    return {
      titles: [
        {
          key: "childid",
          value: "ID"
        },
        {
          key: "nickname",
          value: "代理名称"
        },
        {
          key: "mobile",
          value: "手机"
        },
        {
          key: "btn",
          value: "操作"
        }
      ],
      lists: [],
      maxPage: []
    };
  },
  created() {
    this.fetchData();
  },
  components: {
    TableView
  },
  methods: {
    fetchData(page = 1) {
      this.apiService.agent
        .bindinglist({
          pagesize: 10,
          currentpage: page
        })
        .then(res => {
          this.maxPage = Math.ceil(res.data.total / 10);
          this.lists = res.data.bindinglist;
        });
    },
    changePageClick(data) {
      this.fetchData(data);
    },
    unBindClick(data) {
      this.apiService.agent
        .unbundling({
          agentid: data
        })
        .then(res => {
          this.$vux.toast.text("解绑成功");
          this.fetchData();
        });
    }
  }
};
</script>


<style scoped>

</style>

